/*
 *	SNiFF+ Symtab Interface
 *  Copyright (C) 1998 TakeFive Software GmbH
 *
 *	Author:		Alexander Damisch
 *	Created:	22. Aug 95
 *	Version:	1.5 (27. May 98)
 *
 *	This file contains declarations of functions and data types
 *	needed to access the Symtab - Database of SNiFF+.
 */

/*	Following enum si_Type, describes the possible Types for an Item dumped by SNiFF+ */
#ifndef C_SymTab_API_H
#define C_SymTab_API_H
#ifdef __cplusplus
extern "C" {
#endif
typedef enum  { 
			eTAny=0,				/* no specific type, used as wildcard */
			eTFile,					/* Item is a file */
			eTClass,				/* Item is a class struct or union */
			eTMethodD, 				/* Item is the Declaration of a Method */
			eTMethodI, 				/* Item is the Implementation of a Method */
			eTProc,					/* Item is a non class member Function */
			eTVar, 					/* Item is a variable */
			eTParam, 				/* Item is a Parameter */
			eTMacro, 				/* Item is a Macro */
			eTTypedef, 				/* Item is a Typedef */
			eTEnum,					/* Item is a Enumaration */
			eTEnumItem,				/* Item is a Enumeration Iten */
			eTComment,				/* Item is a Comment */
			eTConst,				/* Item is a constant */
			eTIncl,					/* Item is an include directive */
			eTScope,				/* to identify scopes */
			eTFriend,				/* Item is a friend */
			eTUndef,				/* Item is just known by name as refence */
			eTVersion,				/* Item is a version of an item */
			eTBREAK,				/* Last Token ! token >= are special ones*/
			eTMagic__c=20,			/* to identify magic cookies */
			eTSWITCH,				/* for internal use */
			eTHead,					/* for cm control */
			eTSymbolicName,			/* for cm control */
			eTBranch,				/* for cm control */
			eTLAST					/* for internal use */
			}si_Type;
/*	si_Scope shows the "Scope" in which the item appears. Also used for Queries where
	to search */
typedef enum { 
			eSGlobal=0,				/* scope is global ( wildcard in query ) */
			eSHierarchy,			/* scope is in a Hierarchy */
			eSFile,					/* scope is global to file*/
			eSClass,				/* scope is class*/
			eSMethod,				/* scope is local to method */
			eSProc,					/* scope is local to function*/
			eSEnum,					/* scope is item local to enum */
			eSLAST					/* for internal use */
			}si_Scope;
/*	Specifies the "type of Query" performed on an Item or on the Symtab Database in 
	the Specified Scope */
typedef enum { 
			eQOOHierarchy=0,		/* Queries for the Hierarchy of one Item */
			eQOOFullHierarchy, 		/* Queries for the whole Hierarchy */
			eQOOGetroot,			/* Get rootclass of Item, if NO_ITEM the 
									   root, or dummy root of hierarchy */
			eQOOGetSuper, 			/* Get all Superclasses of Item, if NO_ITEM
									   all superclasses found will be returned */
			eQOOGetSub, 			/* get all Subclasses of Item */
			eQReferredBy,			/* find all CLASSES referred BY Item */ 
			eQReferresTo,			/* find all CLASSES referring TO Item */
			eQMembers, 				/* Queries for all Members of specified */
			eQFindSym, 				/* find all syms in given scope ( wildcard )  */
			eQImplFiles, 			/* finds all Items of type File in global scope */
			eQReferencesTo,			/* finds all items, an eProc or eMethodI references to */
			eQReferencedBy,			/* find all items referring to an item || NOT IMPLEMENTED || */
			eQFileVersionConfig,	/* Get version information for a file */
			eQMAGIC,				/* reseved */
			eQLAST					/* for internal use */
			}si_QType;
			
/*	Flags ,used by the bool is...( Item* ) functions, are representing some additional 
	information for specific Types */
typedef enum { 
			eFOver=0, 				/* Overloaded Item ( Method .... ) */
			eFFriend, 				/* Function or Class is a Friend */
			eFVirtual, 				/* Function is virtual */
			eFAbst, 				/* Function or class is Virtual */
			eFRoot, 				/* Class is rootClass */
			eFSuper, 				/* Class is a superclass */
			eFHeader, 				/* File is a Header */
			eFMember, 				/* Item is a Class, Struct or Union Member Member */
			eFConst,				/* Item is const */
			eFStatic,				/* Item is static */
			eFTemplate,				/* Item is Template ,args are eTParam's in subItems */
			eFPublic,				/* visibility public */
			eFProtected,			/* visibility protected */
			eFPrivate,				/* visibility private */
			eFDefault,				/* used for having default values */
			eFInline,				/* used for eTMethodD to be inline */
			eFMagic=eTMagic__c,		/* as magic aas eTMagic__c */
			eFLAST					/* for internal use */
			}si_Flags;
typedef unsigned long si_ulong;		/* si_ulong used for position in file etc... */
typedef unsigned char si_bool;			
typedef unsigned char si_uchar;
typedef si_ulong SNiFFACCESS;			/* Handle for an communication with SNiFF */

#ifndef NULL
#define NULL 0
#endif

#ifndef TRUE
#define TRUE  ( 1==1 )
#endif /* TRUE */
#ifndef FALSE
#define FALSE !TRUE	
#endif /* FALSE */
#define NO_ITEM  NULL

struct si_Item;					/* forward declaration needed for si_Collection */

/*	The simplest collection possible, contains Items with *prev and *next */
typedef struct  
{
	struct si_Item	*last;
	struct si_Item	*first;
	int 	size;
}si_Collection;


/* si_Item is the structure, containing anything appearing in Symtab - Database. It is collected as Double Linked List */
typedef struct 
{
	si_bool		ovl;			/* is overloaded	*/
	si_bool		fri;			/* is friend		*/
	si_bool		vir;			/* is virtual 		*/
	si_bool		abs;			/* is abstract		*/
	si_bool		roo;			/* is root			*/
	si_bool		sup;			/* is superclass	*/
	si_bool		hea;			/* is header		*/
	si_bool		mem;			/* is member		*/
	si_bool		con;			/* is const			*/
	si_bool		sta;			/* is static		*/
	si_bool		tem;			/* is template		*/
	si_bool		pub;			/* is public		*/
	si_bool		pri;			/* is private		*/
	si_bool		pro;			/* is protected		*/
	si_bool		def;			/* is defaultval	*/
	si_bool		inl;			/* is inline		*/
}si_Flag;
typedef struct 
{
	si_Collection	*subItems;						/*	Pointer to si_Collection of si_Items, that are Members of si_Item */
	si_Collection	*subClass;						/*  Pointer to si_Collection of si_Items that are SubClasses */
	si_Collection	*superClass;					/* 	Pointer to si_Collection of si_Items that are SuperClasses */
	struct si_Item	*from;							/* si_Item* to implementation class,file,method */
	
	si_Scope	scope;								/* Scope in which the Item appears */								
	si_ulong	sPos;								/* Startingpos of si_Item in Implementation */
	si_ulong	ePos;								/* Endpos of si_Item in Implementation */
	
	si_uchar*	typeStr;							/* String of type: Point or Collection */
	si_uchar*	declStr;							/* Declaration string: const Point* or register char */ 
	si_Flag		flags;								/* flags for the is....?? Function */
/* dont touch */
	si_ulong	__magic__cooky__;					/* for absolut internal	use only */
}si_Ingredients;

typedef struct 
{
	si_Ingredients	*_incl;
	si_bool			_hash;	
}si_Resolve;

struct si_Item
{
	struct si_Item*	next;							/*	Pointer to next Item in si_Collection. NO_ITEM if none */
	struct si_Item*	prev;							/*	Pointer to next Item in si_Collection. NO_ITEM if none */
/*-----------------------*/
	si_uchar*	name;								/* String with "Name" of si_Item */
	si_Type 	type;									/* Type of si_Item */
	si_Resolve	take;
	si_ulong		_hash;
};
typedef struct si_Item si_Item;

si_bool		cadd		( si_Collection*, si_Item* );		/* 	add an si_Item to a si_Collection (must use this instead of 
																direct access. Does not prove for double insertion */
si_bool		cremove		( si_Collection*, si_Item* );		/* 	remove an Item from a Collection, and returns TRUE 
																if found that si_Item. ( Item will be not deleted )*/
/*										
 Start of the Symtab Interface user functions 										
*/

/*	This function must be called once when starting 
	to use the interface functions */
void __si__module__init( void );
/* --- Functions for evaluating the flags of an si_Item --- */

si_bool isOverloaded	( si_Item* );				/* TRUE if function or method is overloaded */
si_bool isFriend		( si_Item* );				/* TRUE if si_Item is a friend */
si_bool isVirtual		( si_Item* );				/* TRUE if method is virtual */
si_bool isAbstract		( si_Item* );				/* TRUE if method or class is abstract */
si_bool isRootClass		( si_Item* );				/* TRUE if class or struct root */
si_bool isSuperClass	( si_Item* );				/* TRUE if class or struct is Superclass */
si_bool isHeaderFile	( si_Item* );				/* TRUE if file is Headerfile */
si_bool isMember		( si_Item* );				/* TRUE if Item is member of class struct or union */
si_bool isConst			( si_Item* );				/* TRUE if si_Item is const */
si_bool isTemplate		( si_Item* );				/* TRUE if si_Item is a Template */
si_bool isUseDefault	( si_Item* );				/* TRUE if si_Item has a default value */
si_bool isStatic		( si_Item* );				/* TRUE if si_Item is static */
si_bool isPublic		( si_Item* );				/* TRUE if si_Item is public */
si_bool isPrivate		( si_Item* );				/* TRUE if si_Item is private */
si_bool isProtected		( si_Item* );				/* TRUE if si_Item is protected */
si_bool isInline		( si_Item* );				/* TRUE if si_Item is implemented inline */

/* --- Functions for sniffaccess, the direct interface to a SNiFF+ process ---*/

SNiFFACCESS si_open			( char* session, char*host );	/*	Open a connection to a SNiFF+. si_open tries to start a SNiFF+. */
si_bool		si_close_project( SNiFFACCESS,char* proj );		/*	Close the Project proj, and removes from SNiFF memory .
																The cache for the si_Items will be cleared !*/
si_bool		si_quit		 	( SNiFFACCESS );				/*	Close all project and SNiFF */
si_bool		si_exit		 	( SNiFFACCESS );				/*  Close connection to SNiFF, does not quit SNiFF */
si_bool		si_open_project ( SNiFFACCESS,char* proj );		/*	Load a project in SNiFF+. You have to keep control,
																in what Proj, Scope you are working */
si_bool		si_open_file	( SNiFFACCESS,char* file );		/*	Load file into SNiFF, not implemented yet */

/*	si_Query is the main working function to be called for	searching the Symtab - Database:
		si_QType:		Gives the kind of si_Query that is to be performed.
		si_Scope:		The scope to which the si_Query is restricted. Default is global Scope 
		si_Item:		si_Item, depending to the si_Query, to which the search depends to. Default is NO_ITEM 
*/					
si_Collection* si_Query	( si_QType, si_Scope s, si_Item* i );
/*
	This function returns you the full si_Item, from a hashed one
*/
si_Item* getHashed( si_Item* );
/*
	Clear the cache. Will be called if you call si_close_project
*/
void	clearCache( void );

/* --- Macros and utility functions for easier handling --- */

/* ITER( obj, num )  Obj to Work on, x: unique ITER - number, or string in scope to distinguish resolved Macros  !*/
#define ITER(obj,x)	register si_Item *__si__iterator__tmp__cp##x=obj, *__si__iterator__tmp__orig##x=obj;
#define NEXT( x )		((!(__si__iterator__tmp__orig##x =__si__iterator__tmp__orig##x->next)->take._hash)\
?__si__iterator__tmp__orig##x:getHashed(__si__iterator__tmp__orig##x))
#define RESET( x )		__si__iterator__tmp__orig##x=__si__iterator__tmp__cp##x;


si_Item*	si_mkItem			( void );
si_Item*	si_cloneItem 		( si_Item* );
void		si_purgeItem		( si_Item* );


#ifdef __cplusplus
}
#endif

#endif /* C_SymTab_API_H */
